/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.ArrayList;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import Obliczenia.Obliczenia;

/**
 *
 * @author Darek
 */
public class Gui extends javax.swing.JFrame {
	
	ArrayList<Component> pola = new ArrayList<Component>();
    ArrayList<JTextField> textFields = new ArrayList<JTextField>();
    Obliczenia obliczenia = new Obliczenia();
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	/**
     * Creates new form GUI
     */
    public Gui() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

    	tytulLabel = new javax.swing.JLabel();
        liczbaWierszyTextField = new javax.swing.JTextField();
        wierszeLabel = new javax.swing.JLabel();
        liczbaKolumnTextField = new javax.swing.JTextField();
        kolumnyLabel = new javax.swing.JLabel();
        stanNaturyLabel = new javax.swing.JLabel();
        tabelaPanel = new javax.swing.JPanel();
        minimaksButton = new javax.swing.JButton();
        minimaks2Button = new javax.swing.JButton();
        hurwiczButton = new javax.swing.JButton();
        bayesButton = new javax.swing.JButton();
        savageButton = new javax.swing.JButton();
        rozwiazanieLabel = new javax.swing.JLabel();
        rozwiazanieScrollPane = new javax.swing.JScrollPane();
        rozwiazanieTextArea = new javax.swing.JTextArea();
        wybierzKryteriumLabel = new javax.swing.JLabel();
        kryteriumHurwiczaCheckBox = new javax.swing.JCheckBox();
        wagaTextField = new javax.swing.JTextField();
        wagaLabel = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        plikMenu = new javax.swing.JMenu();
        zakonczMenuItem = new javax.swing.JMenuItem();
        kryteriumMenu = new javax.swing.JMenu();
        minimaksUzytecznosciMenuItem = new javax.swing.JMenuItem();
        minimaksZawoduMenuItem = new javax.swing.JMenuItem();
        kryteriumHurwiczaMenuItem = new javax.swing.JMenuItem();
        kryteriumBayesaMenuItem = new javax.swing.JMenuItem();
        kryteriumSavageaMenuItem = new javax.swing.JMenuItem();


        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        tytulLabel.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
        tytulLabel.setText("Teoria podejmowania decyzji");

        liczbaWierszyTextField.setText("3");
        liczbaWierszyTextField.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        liczbaWierszyTextField.getDocument().addDocumentListener(new LiczbaWierszyTextFieldActionListener());
        
        wierszeLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        wierszeLabel.setText("wiersze");

        liczbaKolumnTextField.setText("4");
        liczbaKolumnTextField.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        liczbaKolumnTextField.getDocument().addDocumentListener(new LiczbaKolumnTextFieldActionListener());

        kolumnyLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        kolumnyLabel.setText("kolumny");

        stanNaturyLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        stanNaturyLabel.setText("Stan natury (moda)");
        stanNaturyLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        
        tabelaPanel.setSize(700, 480);
        tabelaPanel.setPreferredSize( new Dimension( 700, 480 ) );
        tabelaPanel.setMinimumSize( new Dimension( 700, 480 ) );
        
        initializeJPanelGridLayout(liczbaWierszyTextField, liczbaKolumnTextField);
        
        minimaksButton.setText("Minimaks użyteczności");
        minimaksButton.addActionListener(new MinimaksUzytecznosciActionListener());

        minimaks2Button.setText("Minimaks zawodu");
        minimaks2Button.addActionListener(new MinimaksZawoduActionListener());
        
        hurwiczButton.setText("Kryterium Hurwicza");
        hurwiczButton.addActionListener(new KryteriumHurwiczaActionListener());

        bayesButton.setText("Kryterium Bayesa");
        bayesButton.addActionListener(new KryteriumBayesaActionListener());

        savageButton.setText("Kryterium Savage'a");
        savageButton.addActionListener(new KryteriumSavageaActionListener());

        rozwiazanieLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        rozwiazanieLabel.setText("Rozwiązanie:");

        rozwiazanieTextArea.setColumns(20);
        rozwiazanieTextArea.setRows(5);
        rozwiazanieScrollPane.setViewportView(rozwiazanieTextArea);

        wybierzKryteriumLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        wybierzKryteriumLabel.setText("Wybierz kryterium:");
        wybierzKryteriumLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        
        kryteriumHurwiczaCheckBox.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        kryteriumHurwiczaCheckBox.setText("Kryterium Hurwicza");
        kryteriumHurwiczaCheckBox.addItemListener(new KryteriumHurwiczItemListener());            

        kryteriumHurwiczaCheckBox.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        kryteriumHurwiczaCheckBox.setText("Kryterium Hurwicza");

        wagaLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        wagaLabel.setText("min:");
        
        plikMenu.setText("Plik");

        zakonczMenuItem.setText("Zakończ");
        zakonczMenuItem.addActionListener(new ZakonczMenuListener());
        plikMenu.add(zakonczMenuItem);

        jMenuBar1.add(plikMenu);

        kryteriumMenu.setText("Kryterium");

        minimaksUzytecznosciMenuItem.setText("Minimaks użyteczności");
        minimaksUzytecznosciMenuItem.addActionListener(new MinimaksUzytecznosciActionListener());
        kryteriumMenu.add(minimaksUzytecznosciMenuItem);

        minimaksZawoduMenuItem.setText("Minimaks zawodu");
        minimaksZawoduMenuItem.addActionListener(new MinimaksZawoduActionListener());
        kryteriumMenu.add(minimaksZawoduMenuItem);

        kryteriumHurwiczaMenuItem.setText("Kryterium Hurwicza");
        kryteriumHurwiczaMenuItem.addActionListener(new KryteriumHurwiczaActionListener());
        kryteriumMenu.add(kryteriumHurwiczaMenuItem);

        kryteriumBayesaMenuItem.setText("Kryterium Bayesa");
        kryteriumBayesaMenuItem.addActionListener(new KryteriumBayesaActionListener());
        kryteriumMenu.add(kryteriumBayesaMenuItem);

        kryteriumSavageaMenuItem.setText("Kryterium Savagea");
        kryteriumSavageaMenuItem.addActionListener(new KryteriumSavageaActionListener());
        kryteriumMenu.add(kryteriumSavageaMenuItem);

        jMenuBar1.add(kryteriumMenu);
        
        wagaTextField.setText("0.25");
        wagaTextField.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        
        zmienWartosciDoKryteriumHurwicza(false); //zmiana wartosci do checkboxow
        
		setJMenuBar(jMenuBar1);

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(tytulLabel)
                .addGap(352, 352, 352))
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(tabelaPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(285, 285, 285)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(stanNaturyLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(liczbaWierszyTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(wierszeLabel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(liczbaKolumnTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(kolumnyLabel)))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(minimaksButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(minimaks2Button, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(hurwiczButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(bayesButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(savageButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(wybierzKryteriumLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(21, 21, 21)
                                .addComponent(wagaLabel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(wagaTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(kryteriumHurwiczaCheckBox))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(rozwiazanieLabel)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(rozwiazanieScrollPane))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(tytulLabel)
                .addGap(13, 13, 13)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(liczbaWierszyTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(wierszeLabel)
                    .addComponent(liczbaKolumnTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(kolumnyLabel)
                    .addComponent(kryteriumHurwiczaCheckBox))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(stanNaturyLabel)
                    .addComponent(wagaTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(wagaLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(wybierzKryteriumLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(minimaksButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(minimaks2Button)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(hurwiczButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(bayesButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(savageButton))
                    .addComponent(tabelaPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(rozwiazanieLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(rozwiazanieScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 60, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Gui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Gui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Gui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Gui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Gui().setVisible(true);
            }
        });
    }
    
    public void initializeJPanelGridLayout(JTextField liczbaWierszyTextField, JTextField liczbaKolumnTextField){
    	tabelaPanel.removeAll();
    	GridLayout tabelaLayout = new GridLayout(Integer.parseInt(liczbaWierszyTextField.getText()), Integer.parseInt(liczbaKolumnTextField.getText()), 20, 20);
        tabelaPanel.setLayout(tabelaLayout);
        String [] tabela = {"100", "80", "60", "40", "70", "70", "70", "70", "40", "40", "40", "80"};
        textFields.clear();
        if(Integer.parseInt(liczbaKolumnTextField.getText()) == 4 && Integer.parseInt(liczbaWierszyTextField.getText()) == 3){
        	for(int i = 0; i < 12 ; i++){
        		JTextField text = new JTextField(tabela[i]);
            	text.setHorizontalAlignment(SwingConstants.CENTER);
            	textFields.add(text);
        	}
        }
        else{
        	for(int i = 0; i < Integer.parseInt(liczbaKolumnTextField.getText()) * Integer.parseInt(liczbaWierszyTextField.getText()); i++){
            	JTextField text = new JTextField("0");
            	text.setHorizontalAlignment(SwingConstants.CENTER);
            	textFields.add(text);
            }
        }
        
        for(int i =0; i < textFields.size(); i++)
        	tabelaPanel.add(textFields.get(i));
        tabelaPanel.revalidate();
        tabelaPanel.repaint();
    }
    
    public ArrayList<Double> translacjaArrayListyJTextField(){
    	ArrayList<Double> wartosci = new ArrayList<Double>();
    	for( int i = 0; i < textFields.size(); i++){
    		wartosci.add(Double.parseDouble(textFields.get(i).getText()));
    	}
    	return wartosci;
    }
    
    public void warning(JTextField textField){
	    if (Integer.parseInt(textField.getText())<1 || Integer.parseInt(textField.getText())>10){
	        JOptionPane.showMessageDialog(null,
	                "Podaj liczbę z zakresu pomiędzy 1, a 10", "Wprowadzono złą wartość",
	                JOptionPane.ERROR_MESSAGE);
	    }    
	    else{
    		initializeJPanelGridLayout(liczbaWierszyTextField, liczbaKolumnTextField);
	    }
	}
    
    public void zmienWartosciDoKryteriumHurwicza(boolean value){
		wagaTextField.setVisible(value);
		wagaLabel.setVisible(value);
    }
    
	private void podajWartosciWspolczynnikow(int liczbaKolumn) {
		// TODO Auto-generated method stub

		JFrame frame = new JFrame("Podaj wartości wspolczynników");
		JPanel panel = new JPanel();
		JPanel panelZButtonem = new JPanel();
		JButton obliczZWagaButton = new JButton("Oblicz Kryterium Bayesa z współczynnikami");
		
		frame.setSize(600, 160);
		frame.setLayout(new GridLayout(2, 1));
		obliczZWagaButton.addActionListener(new ObliczZWagaButtonListener());
		panelZButtonem.add(obliczZWagaButton);
		
		panel.removeAll();
    	GridLayout tabelaLayout = new GridLayout(2, liczbaKolumn, 5, 5);
        panel.setLayout(tabelaLayout);
        pola.clear();
        
    	for(int i = 0; i < liczbaKolumn; i++){
    		JLabel label = new JLabel(String.valueOf(i+1));
        	label.setHorizontalAlignment(SwingConstants.CENTER);
        	pola.add(label);
        }
    	
    	for(int i = 0; i < liczbaKolumn; i++){
        	JTextField text = new JTextField("0");
        	text.setHorizontalAlignment(SwingConstants.CENTER);
        	pola.add(text);
        }
    	
    	for(int i = 0; i < pola.size(); i++)
        	panel.add(pola.get(i));
        panel.revalidate();
        panel.repaint();
        
        frame.getContentPane().add(panel);
        frame.getContentPane().add(panelZButtonem);
        frame.setVisible(true);
	}
	

	public ArrayList<Double> konwersjaWspolczynnikowNaDouble(){
		ArrayList<Double> tabelaWspolczynnikow =  new ArrayList<Double>();
		double suma = 0.0;
		for(int i = pola.size()/2; i < pola.size(); i++){
			tabelaWspolczynnikow.add(Double.parseDouble(((JTextField) pola.get(i)).getText()));
			suma += Double.parseDouble(((JTextField) pola.get(i)).getText());
		}
		if(suma == 1.0){
			return tabelaWspolczynnikow;
		}
		else{
			JOptionPane.showMessageDialog(null,
	                "Wprowadzono współczynniki, które nie dają w sumie jedynki /n Spróbuj ponownie", "wprowadzono złe dane",
	                JOptionPane.ERROR_MESSAGE);
			return null;
		}
	}

    // Variables declaration - do not modify//GEN-BEGIN:variables

    private javax.swing.JButton bayesButton;
    private javax.swing.JButton savageButton;
    private javax.swing.JButton hurwiczButton;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JLabel kolumnyLabel;
    private javax.swing.JMenuItem kryteriumBayesaMenuItem;
    private javax.swing.JMenuItem kryteriumSavageaMenuItem;
    private javax.swing.JCheckBox kryteriumHurwiczaCheckBox;
    private javax.swing.JMenuItem kryteriumHurwiczaMenuItem;
    private javax.swing.JMenu kryteriumMenu;
    private javax.swing.JTextField liczbaKolumnTextField;
    private javax.swing.JTextField liczbaWierszyTextField;
    private javax.swing.JLabel wagaLabel;
    private javax.swing.JButton minimaks2Button;
    private javax.swing.JButton minimaksButton;
    private javax.swing.JMenuItem minimaksUzytecznosciMenuItem;
    private javax.swing.JMenuItem minimaksZawoduMenuItem;
    private javax.swing.JMenu plikMenu;
    private javax.swing.JLabel rozwiazanieLabel;
    private javax.swing.JScrollPane rozwiazanieScrollPane;
    private javax.swing.JTextArea rozwiazanieTextArea;
    private javax.swing.JLabel stanNaturyLabel;
    private javax.swing.JPanel tabelaPanel;
    private javax.swing.JLabel tytulLabel;
    private javax.swing.JTextField wagaTextField;
    private javax.swing.JLabel wierszeLabel;
    private javax.swing.JLabel wybierzKryteriumLabel;
    private javax.swing.JMenuItem zakonczMenuItem;
    // End of variables declaration//GEN-END:variables



class LiczbaWierszyTextFieldActionListener implements DocumentListener{
	@Override
	public void changedUpdate(DocumentEvent e) {
		// TODO Auto-generated method stub
		warning(liczbaWierszyTextField);
	}

	@Override
	public void insertUpdate(DocumentEvent e) {
		// TODO Auto-generated method stub
		warning(liczbaWierszyTextField);        		
	}

	@Override
	public void removeUpdate(DocumentEvent e) {
		// TODO Auto-generated method stub		
	}	
}

class LiczbaKolumnTextFieldActionListener implements DocumentListener{
	@Override
	public void changedUpdate(DocumentEvent e) {
		// TODO Auto-generated method stub
		warning(liczbaKolumnTextField);
	}

	@Override
	public void insertUpdate(DocumentEvent e) {
		// TODO Auto-generated method stub
		warning(liczbaKolumnTextField);        		
	}

	@Override
	public void removeUpdate(DocumentEvent e) {
		// TODO Auto-generated method stub		
	}	
}

class MinimaksUzytecznosciActionListener implements ActionListener{

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		rozwiazanieTextArea.removeAll();
		rozwiazanieTextArea.setText("Rozwiązanie kryterium minimaksu użyteczności: \n");
		rozwiazanieTextArea.append(obliczenia.minimaksUzytecznosciObliczenia(translacjaArrayListyJTextField(), Integer.parseInt(liczbaKolumnTextField.getText())));
	}
	
}

class MinimaksZawoduActionListener implements ActionListener{

	@Override
	public void actionPerformed(ActionEvent arg0) {
		// TODO Auto-generated method stub
		rozwiazanieTextArea.removeAll();
		rozwiazanieTextArea.setText("Rozwiązanie kryterium minimaksu zawodu: \n");
		rozwiazanieTextArea.append(obliczenia.minimaksZawoduObliczenia(translacjaArrayListyJTextField(), Integer.parseInt(liczbaKolumnTextField.getText())));
	}
	
}

class KryteriumHurwiczaActionListener implements ActionListener{

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		if(kryteriumHurwiczaCheckBox.isSelected()){
			rozwiazanieTextArea.removeAll();
			rozwiazanieTextArea.setText("Rozwiązanie kryterium Hurwicza: \n");
			rozwiazanieTextArea.append(obliczenia.kryteriumHurwiczaObliczenia(translacjaArrayListyJTextField(), Integer.parseInt(liczbaKolumnTextField.getText()), Double.parseDouble(wagaTextField.getText())));
		}
		else{
			JOptionPane.showMessageDialog(null,
	                "Zaznacz opcję, że chcesz obliczyć wartości Kryterium Hurwicza", "Nie zaznaczono wyboru Kryterium Hurwicza",
	                JOptionPane.ERROR_MESSAGE);
		}
	}
	
}

class KryteriumBayesaActionListener implements ActionListener{

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		rozwiazanieTextArea.removeAll();
		rozwiazanieTextArea.setText("Rozwiązanie kryterium Bayesa: \n");
		rozwiazanieTextArea.append(obliczenia.kryteriumBayesaObliczenia(translacjaArrayListyJTextField(), Integer.parseInt(liczbaKolumnTextField.getText()), true, null));
		podajWartosciWspolczynnikow(Integer.parseInt(liczbaKolumnTextField.getText()));
	}
	
}

class KryteriumSavageaActionListener implements ActionListener{

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		rozwiazanieTextArea.removeAll();
		rozwiazanieTextArea.setText("Rozwiązanie kryterium Savagea: \n");
		rozwiazanieTextArea.append(obliczenia.kryteriumSavageaObliczenia(translacjaArrayListyJTextField(), Integer.parseInt(liczbaKolumnTextField.getText()), true));
		//obliczenia.kryteriumSavageaObliczenia(translacjaArrayListyJTextField(), Integer.parseInt(liczbaKolumnTextField.getText()));
	}
	
}

class KryteriumHurwiczItemListener implements ItemListener{

	@Override
	public void itemStateChanged(ItemEvent e) {
		// TODO Auto-generated method stub
		if(e.getStateChange() == ItemEvent.SELECTED){
			zmienWartosciDoKryteriumHurwicza(true);
		}
		else{
			zmienWartosciDoKryteriumHurwicza(false);			
		}
	}
	
}

class ObliczZWagaButtonListener implements ActionListener{

	@Override
	public void actionPerformed(ActionEvent e) {		
		rozwiazanieTextArea.removeAll();
		rozwiazanieTextArea.setText("Rozwiązanie kryterium Bayesa: \n");
		try{
			rozwiazanieTextArea.append(obliczenia.kryteriumBayesaObliczenia(translacjaArrayListyJTextField(), Integer.parseInt(liczbaKolumnTextField.getText()), false, konwersjaWspolczynnikowNaDouble()));
		}
		catch(Exception e1){
			e1.printStackTrace();
		}
	}
	
}

class ZakonczMenuListener implements ActionListener{

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		
	}
	
}

}